package com.stadium.web.service;

import com.fastsite.cache.ehcache.utils.EhCacheUtil;
import com.fastsite.common.api.ApiErrorCodes;
import com.fastsite.common.api.ApiException;
import com.fastsite.common.api.ApiTokenObject;
import com.fastsite.common.api.ApiTokenObjectStore;
import com.fastsite.common.constant.ApiConstant;
import com.stadium.common.StadiumConstant;
import com.stadium.web.domain.TokenUser;
import org.springframework.stereotype.Service;

@Service
public class ApiTokenObjectStoreImpl implements ApiTokenObjectStore {

    @Override
    public ApiTokenObject findApiTokenObject(String token) throws ApiException {
        Object obj = EhCacheUtil.getValue(StadiumConstant.TOKEN_CACHE,token);
        if(obj==null){
            throw new ApiException(ApiErrorCodes.TOKEN_REFUSED,"token已失效，请登陆");
        }
        return (ApiTokenObject)obj;
    }
}
